package com.qiaofang.collectmanage.service.common.utils;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.util.Properties;


public class PropertiesUtil {
    private static final Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
    private PropertiesUtil(){}
    private static Properties prop = new Properties();
    static {
        try {
            InputStream in = PropertiesUtil.class.getClassLoader().getResourceAsStream("application.properties");
            prop.load(in);
            logger.info("加载配置文件application.properties成功");
        } catch (Exception e) {
            logger.error("加载配置文件application.properties失败", e);
            System.exit(-1);
        }
    }

    public static String getProperty(String key) {
        return prop.getProperty(key);
    }

    public static Integer getInteger(String key) {
        String value = getProperty(key);
        try {
            return Integer.valueOf(value);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static Boolean getBoolean(String key) {
        String value = getProperty(key);
        try {
            return Boolean.valueOf(value);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public static Long getLong(String key) {
        String value = getProperty(key);
        try {
            return Long.valueOf(value);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0L;
    }
}
